package com.connection.second.wallpaper.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.connection.second.common.utils.DateUtils;
import com.connection.second.wallpaper.domain.entity.*;
import com.connection.second.wallpaper.domain.page.PaperAlbumRankPage;
import com.connection.second.wallpaper.domain.page.PaperWallRankPage;
import com.connection.second.wallpaper.mapper.PaperAlbumMapper;
import com.connection.second.wallpaper.mapper.PaperClassifyMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.connection.second.wallpaper.mapper.PaperAlbumRankMapper;
import com.connection.second.wallpaper.service.IPaperAlbumRankService;

/**
 * 榜单-专辑排名Service业务层处理
 * 
 * @author Ti
 * @date 2024-11-30
 */
@Service
public class PaperAlbumRankServiceImpl implements IPaperAlbumRankService 
{
    @Autowired
    private PaperAlbumRankMapper paperAlbumRankMapper;
    @Autowired
    private PaperAlbumMapper paperAlbumMapper;
    @Autowired
    private PaperClassifyMapper paperClassifyMapper;

    /**
     * 查询榜单-专辑排名
     * 
     * @param id 榜单-专辑排名主键
     * @return 榜单-专辑排名
     */
    @Override
    public PaperAlbumRank selectPaperAlbumRankById(Long id)
    {
        return paperAlbumRankMapper.selectPaperAlbumRankById(id);
    }

    /**
     * 查询榜单-专辑排名列表
     *
     * @param paperAlbumRank 榜单-专辑排名
     * @return 榜单-专辑排名
     */
    @Override
    @Cacheable(value = "paperAlbumRank", key = "'selectPaperAlbumRankList'+#paperAlbumRank.toString()")
    public List<PaperAlbumRankPage> selectPaperAlbumRankList(PaperAlbumRank paperAlbumRank)
    {
        List<PaperAlbumRankPage> list = new ArrayList<>();
        List<PaperAlbumRank> ranks = paperAlbumRankMapper.selectPaperAlbumRankList(paperAlbumRank);
        for (PaperAlbumRank rank : ranks) {
            PaperAlbumRankPage tmp = new PaperAlbumRankPage();
            BeanUtils.copyProperties(rank, tmp);
            PaperAlbum album = paperAlbumMapper.selectPaperAlbumById(rank.getAlbumId());
            if (ObjectUtil.isNull(album)) {
                continue;
            }
            BeanUtils.copyProperties(album, tmp);
            PaperClassify classify = paperClassifyMapper.selectPaperClassifyById(album.getClassId());
            tmp.setClassName(classify.getName());
            list.add(tmp);
        }
        return list;
    }

    /**
     * 新增榜单-专辑排名
     * 
     * @param paperAlbumRank 榜单-专辑排名
     * @return 结果
     */
    @Override
    public int insertPaperAlbumRank(PaperAlbumRank paperAlbumRank)
    {
        paperAlbumRank.setUpdateTime(DateUtils.getNowDate());
        return paperAlbumRankMapper.insertPaperAlbumRank(paperAlbumRank);
    }

    /**
     * 修改榜单-专辑排名
     * 
     * @param paperAlbumRank 榜单-专辑排名
     * @return 结果
     */
    @Override
    public int updatePaperAlbumRank(PaperAlbumRank paperAlbumRank)
    {
        paperAlbumRank.setUpdateTime(DateUtils.getNowDate());
        return paperAlbumRankMapper.updatePaperAlbumRank(paperAlbumRank);
    }

    /**
     * 批量删除榜单-专辑排名
     * 
     * @param ids 需要删除的榜单-专辑排名主键
     * @return 结果
     */
    @Override
    public int deletePaperAlbumRankByIds(Long[] ids)
    {
        return paperAlbumRankMapper.deletePaperAlbumRankByIds(ids);
    }

    /**
     * 删除榜单-专辑排名信息
     * 
     * @param id 榜单-专辑排名主键
     * @return 结果
     */
    @Override
    public int deletePaperAlbumRankById(Long id)
    {
        return paperAlbumRankMapper.deletePaperAlbumRankById(id);
    }
}
